function ucfirst(str) 
{
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1, str.length-1);
}
function checkEmail(email) {    
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return filter.test(email);    
}
function checkURL(url) {
    var regURL = /^(?:(?:https?|ftp|telnet):\/\/(?:[a-z0-9_-]{1,32}(?::[a-z0-9_-]{1,32})?@)?)?(?:(?:[a-z0-9-]{1,128}\.)+(?:com|net|org|mil|edu|arpa|ru|gov|biz|info|aero|inc|name|[a-z]{2})|(?!0)(?:(?!0[^.]|255)[0-9]{1,3}\.){3}(?!0|255)[0-9]{1,3})(?:\/[a-z0-9.,_@%&?+=\~\/-]*)?(?:#[^ \'\"&<>]*)?$/i;
    return regURL.test(url);
}
function hideSupBlocks()
{
    if ($(".supPane").length) {	
	$(".supPane").addClass("hide");
    }
}
function showModal(modalBlock)
{
    if (!$(modalBlock).length) {
	return false;
    }
    var left = $(modalBlock).innerWidth()/2;
    var top = $(modalBlock).innerHeight()/2;
    top = top >=0 ? top : 0;    
    $(modalBlock).parent().css({
	"margin-left" : -left + "px",
	"margin-top" : -top + "px"
    });	
    $(modalBlock).fadeIn(100);    
    $("div#overlay").fadeIn(100);   
    toEl(modalBlock);    
    return false;
}
function closeModal(modalBlock){
    if (!$(modalBlock).length) {
	alert("error");
	return false;
    }
    
    $(modalBlock + " input[type=text]").val("");
    $(modalBlock).fadeOut(100);
    $("div#overlay").fadeOut(100);
    return false;
}
function openPane(pane)
{
    hideSupBlocks();    
    if (pane && $("#pane" + ucfirst(pane)).length) {	
	$("#pane" + ucfirst(pane)).removeClass("hide");
    }
    if (pane == "map") {	
	$.data(container, "newOpinionMap").refresh();
    }
}
function toEl(selector, duration)
{
    if (!$(selector).length) {
	return false;
    }
    duration = duration || 700;
    $.scrollTo(selector, duration);
}
function showEl(selector, duration)
{
    duration = duration || 700;
    $(selector).slideDown(duration);
}
function hideEl(selector, duration)
{
    duration = duration || 700;
    $(selector).slideUp(duration);
}
function submit(element)
{    
    if($(element).length) {
	$(element).submit();
    }
}
function submitForm(element)
{    
    if($(element).length) {
	$(element).submit();
    }
}
function showStatusMessage(mes, type)
{    
    $.jGrowl(mes, {
	theme: type , 
	life : 5000
    });
}
function disableElement(element)
{
    if (!element) {
	return;
    }
    if (typeof element == "object") {
	element.attr("disabled", "disabled");
    }else {
	if ($(element).length) {
	    $(element).attr("disabled", "disabled");
	}	
    }
}
function enableElement(element)
{
    if (!element) {
	return;
    }
    if (typeof element == "object") {
	element.removeAttr("disabled");
    }else {
	if ($(element).length) {
	    $(element).removeAttr("disabled");
	}	
    }    
}
function errorFunction(XMLHttpRequest, textStatus, errorThrown)
{
    showStatusMessage(errorThrown, "error");
}
function setTab(tabId, obj)
{    
    if (!tabId) {
	return;
    }
    if (!$("ul.infoTabs li").length) {
	return;
    }
    var parent = $(obj).parent().parent();    
    $("ul.infoTabs li", parent).removeClass("active");	
    $("ul.infoTabs li#tab" + ucfirst(tabId), parent).addClass("active");
    
    
    if ($("div.recordAdv div", parent).length) {	
	$("div.recordAdv div.advContent", parent).addClass("hide");	
	$("div.recordAdv div#adv" + ucfirst(tabId), parent).removeClass("hide");	
    }        
    if (tabId == 'video') {	 
	if ($.data(container, "videoSlider") !== undefined) {
	    $.data(container, "videoSlider").reloadShow();
	}	
	if ($.data(container, "opinionVideo") !== undefined) {
	    $.data(container, "opinionVideo").reloadShow();
	}		
    }
    if (tabId == 'map') {
	if ($.data(container, "map") !== undefined) {
	    $.data(container, "map").refresh();	    
	}
	if ($.data(container, "opinionMap") !== undefined) {
	    $.data(container, "opinionMap").refresh();	    
	}
    }
    return false;
}
function reload()
{
    window.location.reload();
}